
act=input("c设置ak sk ，u上传 ，d下载 ?")

if act=="c":
    from Crypto.Cipher import AES
    from binascii import b2a_hex, a2b_hex
    from Crypto.Protocol.KDF import PBKDF2
    from Crypto.Hash import SHA512
    from Crypto.Random import get_random_bytes

    import configparser
    import pathlib
    import os
    import sys 
    root=pathlib.Path(os.path.dirname(os.path.realpath(sys.argv[0])))
    conf = configparser.ConfigParser(allow_no_value=True)
    try:
        conf.read(str(root/"config.ini"), encoding="utf-8")
    except :
        try :
            print("config read for GBK")
            conf.read(str(root/"config.ini"), encoding="GBK")
        except:
            print("配置文件读取错误")
    from secret import *
    ak=input("ak:").encode()
    sk=input("sk:").encode()

    salt = get_random_bytes(16)
    keys = PBKDF2(password, salt, 32, count=100000, hmac_hash_module=SHA512)
    cipher = AES.new(keys, AES.MODE_GCM,salt)
    ciphertext = salt+cipher.encrypt(ak)
    conf.set("config","ak",b2a_hex(ciphertext).decode("utf-8"))
    conf.write(open(str(root/"config.ini"), "w"))

    salt = get_random_bytes(16)
    keys = PBKDF2(password, salt, 32, count=100000, hmac_hash_module=SHA512)
    cipher = AES.new(keys, AES.MODE_GCM,salt)
    ciphertext = salt+cipher.encrypt(sk)
    conf.set("config","sk",b2a_hex(ciphertext).decode("utf-8"))
    conf.write(open(str(root/"config.ini"), "w"))


from ossinc import *
if act=="d":
    getfile(root,'yj.db',"yj/yj.db")
    getfile(root,'config.ini',"yj/config.ini")
    getfile(root,'学生信息.xls',"yj/学生信息.xls")
    getfile(root,'班级座位.xlsx',"yj/班级座位.xlsx")
if act=="u":
    multipartUpload(str(root/"yj.db"),"yj/yj.db")
    multipartUpload(str(root/"config.ini"),"yj/config.ini")
    multipartUpload(str(root/"学生信息.xls"),"yj/学生信息.xls")
    multipartUpload(str(root/"班级座位.xlsx"),"yj/班级座位.xlsx")

a=input("完成！")
